BeforeInsert Event

       

Occurs before new records are inserted into a DataGrid control.

Syntax

Private Sub object_BeforeInsert ([ index As Integer,] cancel As Integer)

The BeforeInsert event syntax has these parts:

Part Description
object An object expression that evaluates to an object in the Applies To list.
index An integer that identifies a control if it is in a control array.
cancel A Boolean expression that determines if a record is added, as described in Settings.

Settings

The settings for cancel are:

Setting Description
True Leaves focus on control and doesn't add a new record
False (Default) Continues with copy and enables change of focus

Remarks

When the user selects the new record (at the bottom of the DataGrid control) and enters a character in one of the cells, the BeforeInsert event is triggered, followed by the BeforeUpdate, AfterUpdate and AfterInsert events.

If your event procedure sets the canceI argument to True, the row isn't inserted and the cell is cleared.

When the BeforeInsert event is triggered, the record has not been added to the database. The new record exists in the DataGrid control's copy buffer until this event procedure ends.

After the AfterInsert event is finished, the new record row in the DataGrid control is reinitialized and the edited record becomes the last row in the DataGrid control.